package fr.utbm.gl52.smartgrid.model.sources;

import java.util.Map;
import java.util.TreeMap;

import fr.utbm.gl52.smartgrid.model.device.Device;
import fr.utbm.gl52.smartgrid.util.properties.Properties;
import fr.utbm.gl52.smartgrid.util.properties.PropertyDouble;
import fr.utbm.gl52.smartgrid.util.properties.PropertyLong;

public abstract class EnergySource extends Device {

	private double powerMin;
	private double powerMax;
	private long lifespan;

	public EnergySource() {
		super();
	}

	public EnergySource(String name, double power, double current,
			double voltage, double efficiency, double powerMin,
			double powerMax, long lifespan) {
		super(name, power, current, voltage, efficiency);
		this.powerMin = powerMin;
		this.powerMax = powerMax;
		this.lifespan = lifespan;
	}

	public double getPowerMin() {
		return this.powerMin;
	}

	public void setPowerMin(double powerMin) {
		this.powerMin = powerMin;
	}

	public double getPowerMax() {

		return this.powerMax;
	}

	public void setPowerMax(double powerMax) {
		this.powerMax = powerMax;
	}

	public long getLifespan() {
		return this.lifespan;
	}

	public void setLifespan(long lifespan) {
		this.lifespan = lifespan;
	}

	public Map<String, Properties<?>> getProperties() {
		TreeMap<String, Properties<?>> prop = (TreeMap<String, Properties<?>>) super
				.getProperties();
		PropertyDouble p1 = new PropertyDouble(
				Messages.getString("EnergySource.0"), this.powerMin, false); //$NON-NLS-1$
		PropertyDouble p2 = new PropertyDouble(
				Messages.getString("EnergySource.1"), this.powerMax, false); //$NON-NLS-1$
		PropertyLong p3 = new PropertyLong(
				Messages.getString("EnergySource.2"), this.lifespan, false); //$NON-NLS-1$
		prop.put(p1.getName(), p1);
		prop.put(p2.getName(), p2);
		prop.put(p3.getName(), p3);
		return prop;
	}

	public void setProperties(Map<String, Properties<?>> map) {
		this.powerMin = (Double) map
				.remove(Messages.getString("EnergySource.0")).getValue(); //$NON-NLS-1$
		this.powerMax = (Double) map
				.remove(Messages.getString("EnergySource.1")).getValue(); //$NON-NLS-1$
		this.lifespan = (Long) map
				.remove(Messages.getString("EnergySource.2")).getValue(); //$NON-NLS-1$
		super.setProperties(map);
	}
}
